package com.service;

import java.net.ConnectException;

import org.restlet.resource.ClientResource;

import src.comom.FakeSigaaResource;

public final class SigaaCalls {
	
	private ClientResource cr;
	FakeSigaaResource resource;
	
	private static final SigaaCalls INSTANCE = new SigaaCalls();
	private SigaaCalls(){
		cr = new ClientResource("http://10.0.2.2:14676");
		resource = cr.wrap(FakeSigaaResource.class);
	}
	public static SigaaCalls getInstance(){
		return INSTANCE;
	}
	
	public String[] getDadosAluno(String username, String password) throws ConnectException{
		String querye, dados, result[] = null;
		querye = "DADOSALUNO"+";"+username+";"+password;
		dados = resource.get(querye);
		
		result = dados.split(";");
		return result;
	}
	
	public double[] getDisciplinaNotas(String username, String password, String nomeDisciplina){
		String querye = "DADOSDISCIPLINA" + ";" + username + ";" + password + ";" + nomeDisciplina;
		
		String dados = resource.get(querye);
		
		String[] result = dados.split(";");
		
		double nota1 = Double.parseDouble(result[0]);
		double nota2 = Double.parseDouble(result[1]);
		double nota3 = Double.parseDouble(result[2]);
		double nota4 = Double.parseDouble(result[3]);
		
		double[] retorno = {nota1, nota2, nota3, nota4};
		
		return retorno;
	}

}
